<div class="page  page-full animation-fade page-menu">
    <div class="page-content">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">菜单管理</h3>
                <div class="panel-actions" id="menuToolbar">
                    <a class="btn btn-primary" href="${base}/admin/sys/menu/create" data-toggle="add">
                        <i class="fa fa-plus" aria-hidden="true"></i> 添加新菜单
                    </a>
                    <a class="btn btn-primary" href="${base}/admin/sys/menu/edit?id={{id}}" data-toggle="edit">
                        <i class="fa fa-pencil-square-o" aria-hidden="true"></i> 编辑菜单
                    </a>
                    <a class="btn btn-danger"  href="${base}/admin/sys/menu/del"  data-toggle="del">
                        <i class="fa fa-trash-o" aria-hidden="true"></i> 删除菜单
                    </a>
                    <a class="btn btn-warning"  href="#" id="importPrivilege">
                        <i class="fa fa-trash-o" aria-hidden="true"></i> 导入权限
                    </a>
                </div>

            </div>
            <div class="panel-body">
                <table id="menuTable">
                    <thead>
                    <tr>
                        <th data-options="{field:'name', align:'center', width:250, rule:'required'}">菜单名称</th>
                        <th data-options="{field:'url', align:'center', width:300}">URL</th>
                        <th data-options="{field:'enabled',align:'center', width:100,formatter:Page.Menu.menuState}">是否可用 </th>
                        <th data-options="{field:'id',align:'center', width:200,formatter:Page.Menu.Operation}">操作 </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>


</div>
<script type="text/javascript">

    $.namespace('Page.Menu');

    Page.Menu = function () {
        return {
            init: function () {
                Page.Menu.initTreeTable();
                $('#importPrivilege').on('click',Page.Menu.import)
            },
            initTreeTable: function () {

                $('#menuTable').boltDataGrid({

                    width:'100%',
                    height:'full-220',
                    toolbar: '#menuToolbar',
                    treeView: true,
                    paging: false,
                    dataUrl: '${base}/admin/sys/menu/getMenuList'
                })
            },
            import:function () {
                var datas = $('#menuTable').boltDataGrid("getSelections"),data = [];
                if(!datas){
                    Bolt.notify("warning", "请选择菜单");
                    return;
                }
                $.each(datas,function(index,value){
                    data.push(value['id']);
                })
                Bolt.ajax('doajax', {
                    data: {'menuId':data.toString()},
                    confirmMsg:"确认要执行此操作码?",
                    url: '${base}/admin/sys/menu/importPrivilege',
                    loadingMask: true
                });
            },
            menuState: function (data) {

                if (data) {
                    return '<span class="label label-primary">已启用</span>';
                } else {
                    return '<span class="label  label-warning ">已禁用</span>';
                }

            },
            Operation:function (value, data) {
                var $html = Bolt.StrBuilder();
                $html.add('<div data-toggle="rowToolbar">');
                $html.add('<a class="btn btn-info" href="${base}/admin/sys/menu/edit?id={{id}}" data-toggle="edit">编辑</a>');
                $html.add('<a class="btn btn-danger" href="${base}/admin/sys/menu/del" data-toggle="del">删除</a>');
                $html.add('</div>');
                return $html.toString();
            }
        }
    }();


    $(document).ready(function () {

        Page.Menu.init();

    });
</script>


